#include <iostream>
using namespace std;
int n; 
string s, t;
int cnt1, cnt0;
void solve()
{
    for(int i = 0; i < n - 1; i++)
    {
        if(cnt1 == 0 || cnt0 == 0) 
        {
            cout << "NO" << endl;
            return;
        }
        if(t[i] == '1') cnt0--;
        else cnt1--;
    }
    cout << "YES" << endl;
}

int main()
{
    int T; cin >> T;
    while(T--)
    {
        cin >> n >> s >> t;
        cnt1 = cnt0 = 0;
        for(int i = 0; i < n; i++)
        {
            if(s[i] == '1') cnt1++;
        }
        cnt0 = n - cnt1;
        solve();
    }
    return 0; 
}